package eduware.util;

import java.util.ArrayList;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * This class pulls the element out of the programlist.xml
 * 
 * @author Dennis Gruner
 * 
 */
public class WebsiteLoader {

	ArrayList<String[]> programList = new ArrayList<String[]>();

	public WebsiteLoader() {
		//opens the programlist.xml
		Document doc = FileHandler
				.getXMLDocument("config/programlist.xml", 500);
		//if the xml file is not found, it will be called on the server
		if (doc == null)
			doc = FileHandler.getXMLDocument(
					"http://www.fbausch.de/se/programlist.xml", 500);
		if (doc == null)
			return;
		//Adds all elments of the xml file to the programSet
		NodeList list = doc.getElementsByTagName("set");
		for (int i = 0; i < list.getLength(); i++) {
			String[] programSet = new String[3];
			Element node = (Element) list.item(i);
			programSet[0] = node.getAttribute("program").trim();
			programSet[1] = node.getAttribute("process").trim();
			programSet[2] = node.getTextContent().trim();
			programList.add(programSet);
		}
	}

	public ArrayList<String[]> getProgramList() {
		//If the xml file was not found or is empty these elements will be added
		if (programList.size() == 0){	
			
			programList.add(new String[] {"firefox", "firefox.exe", "Twitter"});
			programList.add(new String[] {"firefox", "firefox.exe", "Facebook"});
			programList.add(new String[] {"firefox", "firefox.exe", "Kicker"});
			programList.add(new String[] {"firefox", "firefox.exe", "Bundesliga"});
			programList.add(new String[] {"firefox", "firefox.exe", "YouTube"});
			  
			programList.add(new String[] {"internet explorer", "iexplore.exe", "Twitter"});
			programList.add(new String[] {"internet explorer", "iexplore.exe", "Facebook"});
			programList.add(new String[] {"internet explorer", "iexplore.exe", "Kicker"});
			programList.add(new String[] {"internet explorer", "iexplore.exe", "Bundesliga"});
			programList.add(new String[] {"internet explorer", "iexplore.exe", "YouTube"});
			  
			programList.add(new String[] {"chrome", "chrome.exe", "Twitter"});
			programList.add(new String[] {"chrome", "chrome.exe", "Facebook"});
			programList.add(new String[] {"chrome", "chrome.exe", "Kicker"});
			programList.add(new String[] {"chrome", "chrome.exe", "Bundesliga"});
			programList.add(new String[] {"chrome", "chrome.exe", "YouTube"});
			
			programList.add(new String[] {"iron", "iron.exe", "Twitter"});
			programList.add(new String[] {"iron", "iron.exe", "Facebook"});
			programList.add(new String[] {"iron", "iron.exe", "Kicker"});
			programList.add(new String[] {"iron", "iron.exe", "Bundesliga"});
			programList.add(new String[] {"iron", "iron.exe", "YouTube"});
			  
			programList.add(new String[] {"pinball", "pinball.exe", "Pinball"});
			  
			programList.add(new String[] {"minesweeper", "winmine.exe", "Minesweeper"});
			  
			programList.add(new String[] {"solitaire", "sol.exe", "Solitaire"});
			
			return programList;
			
		}else	
			
			//Otherwise the elements out of the xml file will be returned 
			return programList;
	}

}
